package com.spark.lola.controller.ser;

import com.spark.lola.entity.ser.SupervisorRemindLog;
import com.spark.lola.mapper.sup.SupplierInfoMapper;
import com.spark.lola.service.ser.SupervisorRemindLogService;
import com.spark.lola.support.common.entity.ShiroUser;
import com.spark.lola.support.common.util.ResponseBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

/**
 * @author: Zhi-peng wang
 * @date: 2020/07/03 19:08
 **/
@RestController
@RequestMapping("/api/ser/remind")
@Api(value = "/api/ser/remind", tags = "客服提醒日志接口")
public class SupervisorRemindLogController {

    @Autowired
    private SupervisorRemindLogService supervisorRemindLogService;

    @Autowired
    private SupplierInfoMapper supplierInfoMapper;

    @ApiOperation(value = "添加日志")
//    @RequiresPermissions(value = {"m5141", "m5143"}, logical = Logical.OR)
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    @Transactional(rollbackFor = Exception.class)
    public ResponseBean add(@RequestBody SupervisorRemindLog supervisorRemindLog, @SessionAttribute ShiroUser shiroUser) {
        if (supervisorRemindLog.getSalesmanId() == null) {
            return ResponseBean.error("未绑定业务员");
        }
        supervisorRemindLogService.save(supervisorRemindLog);
        supplierInfoMapper.updateRemindCount(
                supplierInfoMapper.findRemindCount(supervisorRemindLog.getSupplierId()) + 1, supervisorRemindLog.getSupplierId());
        return ResponseBean.success();
    }

}
